package cn.tannn.tconfig.demo;

import cn.tannn.tconfig.client.annotation.EnableTconfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;

import java.util.Arrays;

@SpringBootApplication
@EnableConfigurationProperties(TDemoconfig.class)
@Slf4j
@EnableTconfig
public class TconfigDemoApplication {


    @Autowired
    private Environment environment;

    @Autowired
    private TDemoconfig tDemoconfig;

    @Value("${tan.a}")
    private String a;

    @Value("${tan.b}")
    private String b;

    public static void main(String[] args) {
        SpringApplication.run(TconfigDemoApplication.class, args);
    }


    /**
     * 第一时间就拿，看看初始化的时候是不是就将值给赋上了
     */
    @Bean
    ApplicationRunner applicationRunner(){
        log.info("system env active profiles {}", Arrays.toString(environment.getActiveProfiles()));
        return args -> {
            log.info("Value  ==> a {}, b {}", a, b);
            log.info("tDemoconfig {}",tDemoconfig);
        };
    }
}
